begintownscript;

variables;
// These are variables I *typically* use.  Yours may vary.
short bmessage,pcs,seated,leadchar,rctx,rcty;
string custom_m;

body;

beginstate INIT_STATE;

// Setting the crime level because there are soldiers with the party.
	set_crime_tolerance(5);

	turn_off_training(1);

// Making a few quasi-custom NPCs
	set_level(21,5);
	set_name(21,"Colonel Quaerus");
	set_level(22,8);
	set_name(22,"Colonel Jin");
	set_level(32,7);
	set_name(32,"Korigry");
	set_level(33,10);
	set_name(33,"The Decapitator");

// Let the battle begin!
	if(get_flag(8,0) == 0){
		force_instant_terrain_redraw();
		message_dialog("The goblins here have stationed sling-users on their ramparts, and have readied themselves against your oncoming attack.  Fortunately, the tribe seems to be small:  Their raids have been all bark and no bite.","Your men seem relieved at this, even though the battle ahead will still be a very difficult one.  The entirety of the Minnow Tribe seems to have assembled here; your job is to kill them all.");
		set_flag(8,0,1);
	}

// Eliminate everyone if the battle is over.
	if(get_flag(8,0) >= 3){
		pcs = 6;
		while(pcs <= 60){
			if(char_ok(pcs) == TRUE)
				erase_char(pcs);
			pcs = (pcs + 1);
		}
		set_terrain(22,49,0);
		set_terrain(21,49,279);
		set_terrain(23,55,0);
		set_terrain(24,55,0);
		set_terrain(25,55,0);
	}

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	// Warn the party if soldiers start dying
	if((get_flag(10,0) >= 10) && (get_flag(11,0) < 3)){
		message_dialog("All of your soldiers are dead.  This might not be an easy fight from here on out.","No!  It will be a victory.  Imperial virtue will not be struck down by these primitive barbarians!");
		set_flag(11,0,3);
	}
	if((get_flag(10,0) >= 7) && (get_flag(11,0) < 2)){
		message_dialog("Most of your men have died.  Those few that remain appear to be scared for your life.  You belt out a rallying war cry to reassemble their morale, but it seems to have little effect.","");
		set_flag(11,0,2);
	}
	if((get_flag(10,0) >= 4) && (get_flag(11,0) < 1)){
		message_dialog("Your men are beginning to suffer a few casualties.  Not that you didn't expect this, but your men are feeling slightly shocked at watching their comrades die.","Fortunately, you still have the advantage of being human beings-- and that's one element that the goblins could never hope to surpass.");
		set_flag(11,0,1);
	}

	// Are all of the goblins defeated yet?
	if((get_flag(8,0) < 2) && (get_flag(9,0) >= 24)){
		reset_dialog();
		add_dialog_str(0,"It's over.  It's finally over.  The last goblin falls over dead.",0);
		if(get_flag(10,0) >= 10)
			add_dialog_str(1,"Your men gave their lives up valiantly to extinguish this vile tribe.  Now, their sacrifices will lead to a stronger hold on this territory by the intelligent and virtuous settlers who will civilize Morrow Territory.",0);
		if((get_flag(10,0) < 10) && (get_flag(10,0) >= 7))
			add_dialog_str(1,"Most of your men gave their lives up valiantly to extinguish this vile tribe.  Now, their sacrifices will lead to a stronger hold on this territory by the intelligent and virtuous settlers who will civilize Morrow Territory.",0);
		if((get_flag(10,0) < 7) && (get_flag(10,0) >= 4))
			add_dialog_str(1,"Some of your men gave their lives up valiantly to extinguish this vile tribe.  Now, their sacrifices will lead to a stronger hold on this territory by the intelligent and virtuous settlers who will civilize Morrow Territory.",0);
		if((get_flag(10,0) < 4) && (get_flag(10,0) >= 1))
			add_dialog_str(1,"A few of your men gave their lives up valiantly to extinguish this vile tribe.  Now, their sacrifices will lead to a stronger hold on this territory by the intelligent and virtuous settlers who will civilize Morrow Territory.",0);
		if(get_flag(10,0) < 1)
			add_dialog_str(1,"Your men risked their lives valiantly to extinguish this vile tribe.  Fortunately, you suffered no casualties, and have guaranteed a stronger hold on this territory by the intelligent and virtuous settlers who will civilize Morrow Territory.",0);
		add_dialog_str(2,"...",30);
		add_dialog_str(3,"Still, something seems strange.  The village is littered with sleeping pads and there are even a fair number of buildings.  Perhaps you fought the warriors only, and the women and children are hiding in the buildings.",0);
		add_dialog_str(4,"It seems odd that the whole tribe was this small.  They must be hiding somewhere.  You should probably search the village to find what holes these vermin have tried to bury themselves into.",0);
		add_dialog_choice(0,"And kill them all.");
		bmessage = run_dialog(1);
		set_flag(8,0,2);
	}

break;

beginstate 10;

	if(get_flag(8,0) < 2)
		message_dialog("You can't leave yet!  You still have to defeat the goblins here.","");
	if(get_flag(8,0) == 2)
		message_dialog("You still have to investigate the village.  Something seems fishy...","");
	if(get_flag(8,0) >= 3)
		message_dialog("The goblins have fled this mountain-- you have no reason to be here anymore.","");
	block_entry(1);

break;

beginstate 11;

	if(get_flag(13,0) == 0){
		message_dialog("This hut is divided into two rooms.  One room has a few amphorae-- undoubtedly pillaged from the corpses of merchants-- whereas the other has some dice and a few rusty and bent coins.","This must be the most popular area for the goblins to be in; drinking and gambling are common activities for a species of such weak character.");
		set_flag(13,0,1);
	}

break;

beginstate 12;

	if(get_flag(14,0) == 0){
		message_dialog("The goblins are...!","...not here.  The mess hall is empty, save for a few scraps of barely-edible innards strewn about the ground.  Where are they hiding?");
		set_flag(14,0,1);
	}

break;

beginstate 13;

	if(get_flag(15,0) == 0){
		message_dialog("A temple!  Presumably, the goblins would be worshipping their dark and vile gods before making their last stand.","But they aren't.  They're not here.  That couldn't have been the whole tribe, could it have?");
		set_flag(15,0,1);
	}

break;

beginstate 14;

	if(get_flag(16,0) == 0){
		message_dialog("This small room has a remarkably deep hole dug into it.  In the bottom is a large pile of black ashes.  The goblins must cremate and dispose of their dead here.  Still, the room is too small to hold the rest of the tribe...","But there's something strange about the wooden pillar to the west.  It looks like it's been moved about.  A lot.");
		set_flag(16,0,1);
	}

break;

beginstate 15;

	if(get_flag(8,0) == 2){
		reset_dialog();
		add_dialog_str(0,"This column looks as if it's been moved around a LOT.  It's noticeably deeper-laid into the ground than its counterpart, and there's been absolutely no serious attempt to hide the amount of dirt it's displaced.",0);
		add_dialog_str(1,"It's all too tempting to push the column up to the edge of the wall.  Perhaps you'll reveal the secret cranny these pests have bottled themselves into.",0);
		add_dialog_choice(0,"Push it in.");
		add_dialog_choice(1,"Leave it alone.");
		bmessage = run_dialog(0);
		if(bmessage == 2)
			end();
		pcs = 0;
		while(pcs <= 3){
			if(char_ok(pcs) == TRUE){
				if((char_loc_x(pcs) == 21) && (char_loc_y(pcs) == 49)){
					message_dialog("Get out of the way first!","");
					end();
				}
			}
			pcs = (pcs + 1);
		}
		set_terrain(22,49,0);
		set_terrain(21,49,279);
		force_instant_terrain_redraw();
		play_sound(45);
		pause(4);

		set_terrain(24,55,0);
		force_instant_terrain_redraw();
		play_sound(45);
		pause(3);

		set_terrain(23,55,0);
		set_terrain(25,55,0);
		force_instant_terrain_redraw();
		play_sound(45);
		pause(3);

		reset_dialog();
		add_dialog_str(0,"...",0);
		add_dialog_str(1,"And suddenly, your heart falls so quickly that you can feel it squished in-between your toes.",0);
		add_dialog_str(2,"The goblins have, by whatever means, managed to create a secret exit to their village.  They must have some sort of secret route up or down the mountain that Imperial mountain men haven't found yet.",0);
		add_dialog_str(3,"The Minnow Tribe has escaped from your grasp entirely.  Where could those bastards have run off to?!",0);
		add_dialog_choice(0,"Let's follow them!");
		bmessage = run_dialog(1);

		set_flag(8,0,3);
	}

break;

